<?php
session_start();
include('sql.php');
if (isset($_SESSION['id'])) {
    $id = $_SESSION['id'];
    $username = "用户不存在";
    $query = "SELECT username FROM admin_user WHERE id = ?";
    $stmt = $link->prepare($query);
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $username = $row['username'];
    }
?>
<aside class="sidebar col-md-3 col-lg-2 px-0 bg-body-tertiary">
    <a class="navbar-brand d-block text-center text-white py-3" href="home.php"><?php echo $system; ?></a>
    <div class="sidebar-sticky">
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link" href="home.php" aria-current="page">内容配置</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link" href="article.php" aria-current="page">文章</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link" href="banner.php" aria-current="page">首页轮播</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link" href="catalog.php" aria-current="page">栏目</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="admin.php" aria-current="page">管理员</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                    您好，<?php echo $username; ?>
                </a>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="password.php">修改密码</a></li>
                    <li><a class="dropdown-item" href="toset.php?action=out" onclick="return confirm('您确定退出吗？')">退出登录</a></li>
                </ul>
            </li>
        </ul>
    </div>
</aside>
<?php } else {
    echo "未登入";
} ?>